import {Page} from '@/base/Page';
import {SignLog} from '@/base/model/SignLog';
import {getSignLogList,deleteSignLog} from '@/base/api/SignLogApi';
import {isEmpty} from '@/base/util/Strings';
import {infoBloc} from "@/store/module/Info";
import {News} from "@/base/model/News";

class Form {
  createBegin = '';
  createEnd = '';
  phone = '';
  nickname = '';
  date = [];
}

export class SignLogBloc {
  form = new Form();
  paged: Page<SignLog> = new Page<SignLog>([], 0, 1, 15, 0, []);
  loading = false;

  load(pageIndex: number, pageSize: number) {
    if (!isEmpty(this.form.date) && !isEmpty(String(this.form.date[0]))) {
      // @ts-ignore
      this.form.createBegin = this.form.date[0].getTime() || '';
      // @ts-ignore
      this.form.createEnd = this.form.date[1].getTime() + 24 * 60 * 60 * 1000 || '';
    } else {
      this.form.createBegin = '';
      this.form.createEnd = '';
    }
    this.loading = true;
    return getSignLogList({
      pageIndex,
      pageSize,
      sortDirection: 'DESC',
      nickname: this.form.nickname,
      phone: this.form.phone,
      createBegin: this.form.createBegin,
      createEnd: this.form.createEnd
    }).then((res) => {

      this.paged = res.data;
      console.log(this.paged.items[0]);
    }).finally(() => {
      this.loading = false;
    });
  }
  reset() {
    this.form = new Form();
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.load(this.paged.pageIndex, this.paged.pageSize);

  }
  // removeItem(dateItem: SignLog) {
  //   this.loading = true;
  //   return deleteSignLog(dateItem.logid)
  //     .finally(() => {
  //       this.loading = false;
  //     });
  // }
  // getNickName(memberid: number) {
  //   const item = this.paged.items.find(x => x.memberid === memberid);
  //   return item == null ? '' : item.name;
  // }
  // getphone(memberid: number) {
  //   const item = this.paged.extras.find(x => x.id === memberid);
  //   return item == null ? '' : item.phone;
  // }
}
